package ui.views;

import javax.swing.JDialog;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.awt.SystemColor;

public class UICredentialError extends JDialog {

	private static final long serialVersionUID = 2956703735989721074L;
	private JPanel bodyPanel;
	private JLabel errorMessageLabel;
	private Dimension dimension;
	
	/**
	 * class's singleton
	 */
	private static UICredentialError credentialErrorInstance;

	public void main() {
		try {
			getCredentialErrorInstance().setVisible(true);
			Thread.sleep(2000);
			getCredentialErrorInstance().setVisible(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	private UICredentialError() {
		setBackground(SystemColor.info);
		getContentPane().setBackground(new Color(255, 99, 71));
		setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
		setIconImage(Toolkit.getDefaultToolkit().getImage(UICredentialError.class.getResource("/ui/recources/fridge.png")));
		setBounds(100, 100, 320, 150);
		
		dimension = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation(dimension.width/2-getSize().width/2, dimension.height/2-getSize().height/2);
		
		bodyPanel = new JPanel();
		bodyPanel.setBackground(new Color(255, 99, 71));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(bodyPanel, GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addComponent(bodyPanel, GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
		);
		
		errorMessageLabel = new JLabel("WRONG USERNAME OR PASSWORD");
		errorMessageLabel.setForeground(Color.WHITE);
		errorMessageLabel.setBackground(new Color(255, 99, 71));
		errorMessageLabel.setFont(new Font("Calibri", Font.PLAIN, 18));
		errorMessageLabel.setHorizontalAlignment(SwingConstants.CENTER);
		GroupLayout gl_bodyPanel = new GroupLayout(bodyPanel);
		gl_bodyPanel.setHorizontalGroup(
			gl_bodyPanel.createParallelGroup(Alignment.LEADING)
				.addComponent(errorMessageLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
		);
		gl_bodyPanel.setVerticalGroup(
			gl_bodyPanel.createParallelGroup(Alignment.LEADING)
				.addComponent(errorMessageLabel, GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
		);
		bodyPanel.setLayout(gl_bodyPanel);
		getContentPane().setLayout(groupLayout);
	}

	public static UICredentialError getCredentialErrorInstance(){
		if(credentialErrorInstance == null)
			credentialErrorInstance = new UICredentialError();
		return credentialErrorInstance;
	}
}
